﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;
using System.Threading;

namespace PSE.Deployment.TeamFoundation.Communication
{
    public class TeamProjects : CommunicationBase
    {
        #region Singleton
        private static TeamProjects instance;
        protected TeamProjects() 
        {
            Communication.VersionControl.Instance.TraceEvent += (sender, e) => RaiseEventTrace(e);
        }
        public static TeamProjects Instance
        {
            get
            {
                if (instance == null)
                {
                    Mutex mutex = new Mutex();
                    mutex.WaitOne();

                    if (instance == null)
                        instance = new TeamProjects();

                    mutex.Close();
                }
                return instance;
            }
        }
        #endregion Singleton

        public TeamProject[] GetTeamProjects()
        {
            RaiseEventTrace("Obtendo os Teams Projects");

            VersionControlServer versionControl = Communication.VersionControl.Instance.GetVersionControlServer();

            return versionControl.GetAllTeamProjects(true);
        }

    }
}
